package edu.po.au.server.service;

import javax.jdo.PersistenceManager;

import com.google.api.server.spi.config.Api;
import com.google.api.server.spi.config.ApiMethod;

import edu.po.au.server.EPConstants;
import edu.po.au.server.PMF;
import edu.po.au.server.data.ProductDAL;
import edu.po.au.server.domain.Product;


@Api(name = "au", version=EPConstants.API_VERSION, 
clientIds = {com.google.api.server.spi.Constant.API_EXPLORER_CLIENT_ID, EPConstants.WEB_CLIENT_ID}, 
audiences = {EPConstants.ANDROID_AUDIENCE}, 
scopes={"https://www.googleapis.com/auth/userinfo.email"})
public class DataEndpoint {
	
	@SuppressWarnings({ "unchecked", "unused" })
	@ApiMethod(name = "data.init", path="data/initial")
	public Product initData(){
		Product product = null;
		PersistenceManager mgr = null;
		try{
			mgr = getPersistenceManager();
			product = ProductDAL.startup(mgr);
		}
		finally{
			mgr.close();
		}
		return product;
	}
	
	private static PersistenceManager getPersistenceManager() {
		return PMF.get().getPersistenceManager();
	}


}
